home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / misc1 / iv26_w30.zip / EXAMPLES / IDRAW / SELECTIO.H < prev    next >
C/C++ Source or Header  |  1992-03-05  |  6KB  |  177 lines

  1. /*
  2.  * Copyright (c) 1987, 1988, 1989 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Stanford not be used in advertising or
  9.  * publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Stanford makes no representations about
  11.  * the suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  20.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  */
  22.  
  23. // $Header: selection.h,v 1.14 89/10/09 14:49:24 linton Exp $
  24. // declares classes Selection and NPtSelection.
  25.  
  26. #ifndef selection_h
  27. #define selection_h
  28.  
  29. #include <InterViews/Graphic/picture.h>
  30. #include <math.h>
  31.  
  32. // Declare imported types.
  33.  
  34. class Rubberband;
  35. class RubberVertex;
  36. class State;
  37. class istream;
  38. class ostream;
  39.  
  40. // PostScript file format changes.
  41.  
  42. static const int ORIGINALVERSION = 1;      // original format
  43. static const int FGCOLORVERSION = 2;      // added foreground color
  44. static const int NONREDUNDANTVERSION = 3; // eliminated unnecessary text
  45.                       // pattern and duplication of
  46.                       // font name, transformation matrix,
  47.                       // poly points, and text data
  48. static const int FGANDBGCOLORVERSION = 4; // added background color and
  49.                       // RGB values for overriding names;
  50.                       // used graylevel to eliminate
  51.                       // redundant patternfill data
  52. static const int GRIDSPACINGVERSION = 5;  // added grid spacing
  53. static const int NONROTATEDVERSION = 6;      // replaced rotation of drawing with
  54.                       // rotation of view for landscape
  55. static const int TEXTOFFSETVERSION = 7;      // changed text positions on screen
  56.                       // and improved accuracy of
  57.                       // text positions on printout
  58.  
  59. // Other constants.
  60.  
  61. static const int ARROWHEIGHT = 8;      // how long arrows are in points
  62. static const int ARROWWIDTH = 4;       // how wide arrows are in points
  63. static const int BUFSIZE = 256;           // size of buffer for reading data
  64. static const int HDSIZE = 5;           // how wide handles are in points
  65.  
  66. // A Selection can draw handles around itself and create a reshaped
  67. // copy of itself.
  68.  
  69. extern const char* startdata;           // signals place to read valid data
  70.  
  71. class Selection : public Picture {
  72. public:
  73.  
  74.     Selection(Graphic* = nil);
  75.     ~Selection();
  76.  
  77.     Graphic* Copy();
  78.     boolean HasChildren();
  79.  
  80.     void GetPaddedBox(BoxObj&);
  81.     void DrawHandles(Painter*, Canvas*);
  82.     void EraseHandles(Painter*, Canvas*);
  83.     void RedrawHandles(Painter*, Canvas*);
  84.     void RedrawUnclippedHandles(Painter*, Canvas*);
  85.     void ResetHandles();
  86.  
  87.     virtual boolean ShapedBy(Coord, Coord, float);
  88.     virtual Rubberband* CreateShape(Coord, Coord);
  89.     virtual Selection* GetReshapedCopy();
  90.  
  91.     virtual void WriteData(ostream&);
  92.  
  93. protected:
  94.  
  95.     void Skip(istream&);
  96.     void ReadVersion(istream&);
  97.     void ReadGridSpacing(istream&, State*);
  98.     void ReadGS(istream&, State*);
  99.     void ReadPictGS(istream&, State*);
  100.     void ReadTextGS(istream&, State*);
  101.     void ReadBrush(istream&, State*);
  102.     void ReadFgColor(istream&, State*);
  103.     void ReadBgColor(istream&, State*);
  104.     void ReadFont(istream&, State*);
  105.     void ReadPattern(istream&, State*);
  106.     void ReadTransformer(istream&);
  107.     float CalcGrayLevel(int);
  108.  
  109.     void WriteVersion(ostream&);
  110.     void WriteGridSpacing(ostream&, State*);
  111.     void WriteGS(ostream&);
  112.     void WritePictGS(ostream&);
  113.     void WriteTextGS(ostream&);
  114.     void WriteBrush(ostream&);
  115.     void WriteFgColor(ostream&);
  116.     void WriteBgColor(ostream&);
  117.     void WriteFont(ostream&);
  118.     void WritePattern(ostream&);
  119.     void WriteTransformer(ostream&);
  120.  
  121.     virtual void CreateHandles();
  122.     void DeleteHandles();
  123.  
  124.     Rubberband* handles;    // contains handles outlining Selection
  125.  
  126.     static char buf[BUFSIZE];    // contains storage for reading data
  127.     static int versionnumber;    // stores version of drawing read from file
  128.  
  129. };
  130.  
  131. // An NPtSelection knows how to create handles, read or write its
  132. // points, and draw arrowheads so many subclasses can reuse the same
  133. // code.
  134.  
  135. class NPtSelection : public Selection {
  136. public:
  137.  
  138.     NPtSelection(Graphic*);
  139.  
  140.     virtual int GetOriginal(const Coord*&, const Coord*&);
  141.     boolean ShapedBy(Coord, Coord, float);
  142.     Rubberband* CreateShape(Coord, Coord);
  143.     Selection* GetReshapedCopy();
  144.  
  145. protected:
  146.  
  147.     void ReadPoints(istream&, const Coord*&, const Coord*&, int&);
  148.     void WriteData(ostream&);
  149.  
  150.     virtual RubberVertex* CreateRubberVertex(Coord*, Coord*, int, int);
  151.     virtual Selection* CreateReshapedCopy(Coord*, Coord*, int);
  152.     void CreateHandles();
  153.     void TotalTransform(Coord*, Coord*, int);
  154.     void InvTotalTransform(Coord*, Coord*, int);
  155.     int ClosestPoint(Coord*, Coord*, int, Coord, Coord);
  156.  
  157.     boolean LeftAcont(Coord, Coord, Coord, Coord, PointObj&, Graphic*);
  158.     boolean RightAcont(Coord, Coord, Coord, Coord, PointObj&, Graphic*);
  159.     boolean LeftAints(Coord, Coord, Coord, Coord, BoxObj&, Graphic*);
  160.     boolean RightAints(Coord, Coord, Coord, Coord, BoxObj&, Graphic*);
  161.     void drawLeftA(Coord, Coord, Coord, Coord, Canvas*, Graphic*);
  162.     void drawRightA(Coord, Coord, Coord, Coord, Canvas*, Graphic*);
  163.     float MergeArrowHeadTol(float, Graphic*);
  164.     boolean ArrowHeadcont(Coord, Coord, Coord, Coord, PointObj&, Graphic*);
  165.     boolean ArrowHeadints(Coord, Coord, Coord, Coord, BoxObj&, Graphic*);
  166.     void drawArrowHead(Coord, Coord, Coord, Coord, Canvas*, Graphic*);
  167.     void SetCTM(Coord, Coord, Coord, Coord, Graphic*, boolean);
  168.     void RestoreCTM(Graphic*);
  169.     float Slope(float, float);
  170.  
  171.     const char* myname;        // tells which NPtSelection subclass this is
  172.     RubberVertex* rubbervertex;    // tells us how the user wants to reshape us
  173.  
  174. };
  175.  
  176. #endif
  177.